<template>
	<view>
		<block v-for="(item,index) in list" :key="index">
			<view class="top-bigbox">
				<view class="todo">{{item.company_name}}</view>
				<view class="flex">
					<view class="men-name">驻企人员:</view>
					<view class="names">{{item.user_name}}</view>
				</view>
			</view>
			<view class="flex btm-bigbox">
				<view class="flex del-box" @tap="handleClickDel(item.id)">
					<img class="del-img" src="../../static/icon/icon_trash.png" alt="">
					<view class="del">删除</view>
				</view>
				<view class="flex change-box" @tap="handleClickChange(item)">
					<img class="change-img" src="../../static/icon/icon_edit.png" alt="">
					<view class="change">编辑</view>
				</view>
				<view class="look-box" @tap="handleClickRecruit(item)">
					查看企业人才
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				msg: '',
				token: '',
				page: 1,
				list: [],
			}
		},
		methods: {
			// 取token
			getToken() {
				try {
					const value = uni.getStorageSync('login_key');
					if (value) {
						this.token = value;
					}
				} catch (e) {
					// error
				}
			},
			// 点击查看企业人才
			handleClickRecruit(item) {
				// console.log(item)
				let company_id = item.company_id
				uni.navigateTo({
					url: '/pages/talent_pool/my_talent_list?company_id=' + company_id
				})
			},
			// 点击新增跳转新增页面
			handleClickAdd() {
				uni.navigateTo({
					url: '/pages/work_bench/addStation'
				})
			},
			// 点击修改跳页面传参数
			handleClickChange(item) {
				// console.log(item);
				let items = JSON.stringify(item)
				uni.navigateTo({
					url: '/pages/work_bench/addStation?items=' + items
				})
			},
			// 点击删除
			handleClickDel(id) {
				// console.log(id);
				this.getToken()
				// 发请求
				uni.showModal({
					title: '温馨提示',
					content: '确认要删除吗？',
					showCancel: true,
					cancelText: '取消',
					confirmText: '确认',
					success: async res => {
						if (res.confirm) {
							let url = this.ServicesApi.delStation;
							let data = {
								id,
							};
							let result = await this.Services.post(url, data);
							if (result.code == this.StatusCode.SUCCESS_CODE) {
								uni.showToast({
									icon: 'none',
									title: result.msg,
								});
								this.getList();
							} else {
								uni.showToast({
									icon: 'none',
									title: result.msg,
								});
							}
							// uni.request({
							//     url: this.ServicesApi.delStation, 
							// 	method:'POST',
							// 	header: {
							// 		"content-type":"application/x-www-form-urlencoded"
							// 	},
							//     data: {
							// 		token:this.token,
							// 		id:id,
							//     },
							//     success: (res) => {
							// 		// console.log(res.data)
							// 		if(res.data.code == 0){
							// 			this.msg=res.data.msg
							// 			return false
							// 		}else{
							// 			// uni.navigateTo({
							// 			// 	url:'./companyType'
							// 			// })
							// 			uni.showToast({
							// 				title: res.data.msg
							// 			});
							// 		}
							// 		this.getList();
							//     },
							// });
						} else if (res.cancel) {

						}
					}
				});

			},
			// 请求岗位参数
			async getList() {
				this.getToken()
				// 发请求
				let url = this.ServicesApi.stationIndex;
				let data = {
					user_id: '', //搜索用户id 用户列表接口
					company_id: '', //搜索企业id 企业列表接口
					page: this.page,
					limit: 10
				};
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					this.list = result.data.list;
				} else {
					uni.showToast({
						icon: 'none',
						title: result.msg,
					});
				}
				// uni.request({
				//     url: this.ServicesApi.stationIndex, 
				// 	method:'POST',
				// 	header: {

				// 		"content-type":"application/x-www-form-urlencoded"
				// 	},
				//     data: {
				// 		token:this.token,
				// 		user_id:'',  //搜索用户id 用户列表接口
				// 		company_id:'',  //搜索企业id 企业列表接口
				// 		page:this.page,
				// 		limit:10
				//     },
				//     success: (res) => {
				// 		// console.log(res.data.data.list)
				// 		this.list = res.data.data.list;
				//     }
				// });
			},
		},
		mounted() {
			this.getList()
		},
		onShow: function(e) {
			// #ifndef H5
				let pages = getCurrentPages();
				let currPage = pages[pages.length - 1];
				if (currPage.data && currPage.data.isDoRefresh == true) {
					currPage.data.isDoRefresh = false;
					// console.log('s刷新');
					this.getList()
				} else {
					//不用刷新
				}
			// #endif
			// #ifdef H5
			this.getList()
			// #endif
		}
	}
</script>

<style scoped lang="stylus">
	.top-bigbox {
		padding: 36upx 68upx;
		background: #fff;

		.todo {
			font-size: 36upx;
			color: #333333;
			margin-bottom: 18upx;
		}

		.men-name {
			font-size: 30upx;
			color: #666666;
			margin-right: 20upx;
		}

		.names {
			font-size: 30upx;
			color: #333333;
		}
	}

	.btm-bigbox {
		height: 100upx;
		align-items: center;
		border-top: 1upx solid #DBDBDB;
		// justify-content:space-around;
		background: #fff;
		margin-bottom: 30upx;

		.del-box {
			align-items: center;
			margin-left: 68upx;
			margin-right: 50upx;

			.del-img {
				height: 26upx;
				width: 24upx;
			}

			.del {
				font-size: 30upx;
				color: #666666;
				margin-left: 10upx;
			}
		}

		.change-box {
			align-items: center;
			margin-right: 178upx;

			.change-img {
				height: 26upx;
				width: 24upx;
			}

			.change {
				font-size: 30upx;
				color: #666666;
				margin-left: 10upx;
			}
		}

		.look-box {
			width: 228upx;
			height: 64upx;
			background: linear-gradient(270deg, rgba(0, 106, 231, 1) 0%, rgba(66, 157, 255, 1) 100%);
			border-radius: 4upx;
			text-align: center;
			line-height: 64upx;
			color: #fff;
			font-size: 30upx;
		}

	}
</style>
